﻿// DBauthDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "Aries.h"
#include "DBauthDlg.h"
#include "afxdialogex.h"



// CDBauthDlg 对话框

IMPLEMENT_DYNAMIC(CDBauthDlg, CDialogEx)

CDBauthDlg::CDBauthDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDBauthDlg::IDD, pParent)
{

}

CDBauthDlg::~CDBauthDlg()
{
}

void CDBauthDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_USERNAME, m_Uid);
	DDX_Control(pDX, IDC_EDIT_PASSWORD, m_Pwd);
	DDX_Control(pDX, IDC_MSG, m_Message);
}


BEGIN_MESSAGE_MAP(CDBauthDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CDBauthDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CDBauthDlg 消息处理程序


void CDBauthDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	char *conninfo;	
	//PGconn *conn;
	CString username;
	CString password;
	CString constr;
	CString sqlstr;
	int iLen,iSize;
	
	m_Uid.GetWindowText(username);
	m_Pwd.GetWindowText(password);
	//if(username==_T("")&password==_T(""))   
	//AfxMessageBox(_T("用户名和密码不能为空"));

	constr.Format(_T("dbname=stock user=%s password=%s"),username,password);	
	iLen=constr.GetLength();
	iSize = WideCharToMultiByte(CP_ACP, 0, constr, -1, NULL, 0, NULL, NULL);
	conninfo = (char*)malloc((iSize+1));
	WideCharToMultiByte(CP_ACP, 0, constr, -1, conninfo, iSize, NULL, NULL);
	m_Conn = PQconnectdb(conninfo);
	/* Check to see that the backend connection was successfully made */
    if (PQstatus(m_Conn) != CONNECTION_OK)
    {
      	m_Message.SetWindowText(_T("用户名或密码错误，请重新输入!!!"));		
    }
	else
	{
		m_Message.SetWindowText(_T("数据库连接成功!!!"));
		free(conninfo);	
		CDialog::OnOK();
	}
}
